<?php

namespace Blog\Controller;

use Common\Controller\AddonController;
use Think\Hook;

class BaseController extends AddonController
{
    public function _initialize()
    {
        parent::_initialize();
        $ar = D('Article');
        $st_dates = $ar->order('st_date desc')->get_date_st(10); // 十天归档
        $comment_map = [
            'post_id' => ['exp', 'in ' . $ar->where(['status' => 1])->field('id')->buildSql()],
            'uid'=>['not in', C('ADMINISTRATOR_USER')],
        ];
        $new_comments = D('ArticleReply')->where($comment_map)->limit(10)->order('create_time desc')->select();
        $new_articles = $ar->where(['status'=>1])->limit(10)->select();
        $category_list = D('Category')->getChilds(C('category_code'), 10);
        Hook::listen('blog_init', $p = [
            'st_dates' => &$st_dates,
            'new_comments' => &$new_comments,
            'new_articles'=>$new_articles,
            'category_list'=>$category_list,
            'assign' => function ($k, $v) {
                $this->assign($k, $v);
            }]);
        $this->assign('new_comments', $new_comments);
        $this->assign('new_articles', $new_articles);
        $this->assign('category_list', $category_list);
        $this->assign('st_dates', $st_dates);
    }
}